package top.younote.cherry.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.stereotype.Service;
import top.younote.cherry.event.ReceiveEventMessageEvent;
import top.younote.cherry.mapper.CherryEventMapper;
import top.younote.cherry.model.entity.CherryEventEntity;
import top.younote.cherry.model.vo.MessageEventVO;
import top.younote.cherry.service.CherryEventService;

import java.util.Date;

/**
 * @Description:
 * @Author: duanluyao
 * @CreateTime: 2021/9/28 19:46:53
 */
@Service
public class CherryEventServiceImpl implements CherryEventService {
    @Autowired
    private CherryEventMapper cherryEventMapper;
    @Autowired
    private ApplicationEventPublisher publisher;

    @Override
    public void processMessageEvent(MessageEventVO message) {
        CherryEventEntity entity = new CherryEventEntity();
        entity.setEventName(message.getDesc());
        entity.setEventType((byte) 0);
        entity.setEventDesc(message.getDesc());
        entity.setEventDate(new Date());
        entity.setEventUser(message.getEventUser());
        cherryEventMapper.insert(entity);
        publisher.publishEvent(new ReceiveEventMessageEvent(message));
    }
}
